﻿
using System;
using System.Text;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Util;
using Demo_G.O.S.E.ServerEngine.Common;
using Demo_G.O.S.E.ServerEngine.Network;

namespace Demo_G.O.S.E.ServerEngine.Skill
{

    public class BaseSkill
    {
        private Skills m_Owner;
        private SkillInfo m_Info;
        private ushort m_Base;
        private ushort m_Cap;
        private SkillLock m_Lock;

        public override string ToString()
        {
            return String.Format( "[{0}: {1}]", Name, Base );
        }

        public BaseSkill( Skills owner, SkillInfo info )
        {
            m_Owner = owner;
            m_Info = info;

            if ( m_Lock < SkillLock.Up || m_Lock > SkillLock.Locked )
            {
                Console.WriteLine( "Bad skill lock -> {0}.{1}", owner.Owner, m_Lock );
                m_Lock = SkillLock.Up;
            }
        }

        public BaseSkill( Skills owner, SkillInfo info, int baseValue, int cap, SkillLock skillLock )
        {
            m_Owner = owner;
            m_Info = info;
            m_Base = (ushort)baseValue;
            m_Cap = (ushort)cap;
            m_Lock = skillLock;
        }

        public void SetLockNoRelay( SkillLock skillLock )
        {
            if ( skillLock < SkillLock.Up || skillLock > SkillLock.Locked )
                return;

            m_Lock = skillLock;
        }

        public Skills Owner
        {
            get { return m_Owner; }
        }

        public SkillName SkillName
        {
            get { return (SkillName)m_Info.SkillID; }
        }

        public int SkillID
        {
            get { return m_Info.SkillID; }
        }

        [CommandProperty( AccessLevel.Counselor )]
        public string Name
        {
            get { return m_Info.Name; }
        }

        public SkillInfo Info
        {
            get { return m_Info; }
        }

        [CommandProperty( AccessLevel.Counselor )]
        public SkillLock Lock
        {
            get { return m_Lock; }
        }

        public int BaseFixedPoint
        {
            get { return m_Base; }
            set
            {
                if ( value < 0 )
                    value = 0;
                else if ( value >= 0x10000 )
                    value = 0xFFFF;

                ushort sv = (ushort)value;

                int oldBase = m_Base;

                if ( m_Base != sv )
                {
                    //m_Owner.Total = ( m_Owner.Total - m_Base ) + sv;

                    m_Base = sv;

                    m_Owner.OnSkillChange( this );

                    //BaseMobile m = m_Owner.Owner;

                    //if ( m != null )
                    //    m.OnSkillChange( SkillName, (double)oldBase / 10 );
                }
            }
        }

        [CommandProperty( AccessLevel.Counselor, AccessLevel.GameMaster )]
        public double Base
        {
            get { return ( (double)m_Base / 10.0 ); }
            set { BaseFixedPoint = (int)( value * 10.0 ); }
        }

        public int CapFixedPoint
        {
            get { return m_Cap; }
            set
            {
                if ( value < 0 )
                    value = 0;
                else if ( value >= 0x10000 )
                    value = 0xFFFF;

                ushort sv = (ushort)value;

                if ( m_Cap != sv )
                {
                    m_Cap = sv;

                    m_Owner.OnSkillChange( this );
                }
            }
        }

        [CommandProperty( AccessLevel.Counselor, AccessLevel.GameMaster )]
        public double Cap
        {
            get { return ( (double)m_Cap / 10.0 ); }
            set { CapFixedPoint = (int)( value * 10.0 ); }
        }

        private static bool m_UseStatMods;

        public static bool UseStatMods
        {
            get { return m_UseStatMods; }
            set { m_UseStatMods = value; }
        }

        public int Fixed
        {
            get { return (int)( Value * 10 ); }
        }

        [CommandProperty( AccessLevel.Counselor )]
        public double Value
        {
            get
            {
                //There has to be this distinction between the racial values and not to account for gaining skills and these skills aren't displayed nor Totaled up.
                double value = this.NonRacialValue;

                //double raceBonus = m_Owner.Owner.RacialSkillBonus;

                //if ( raceBonus > value )
                //    value = raceBonus;

                return 0;
            }
        }

        [CommandProperty( AccessLevel.Counselor )]
        public double NonRacialValue
        {
            get { return 0; }
        }

        public void Update()
        {
            m_Owner.OnSkillChange( this );
        }
    }
}

